import { Component, OnInit, ViewChild } from '@angular/core';
import { STColumn, STComponent } from '@delon/abc/st';
import { SFComponent, SFSchema, SFSelectWidgetSchema, SFUISchema } from '@delon/form';
import { ShipperBaseService } from '@shared';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { RebateManagementService } from '../../services/rebate-management.service';
import { NzButtonSize } from 'ng-zorro-antd/button';

@Component({
  selector: 'app-parter-channel-rebate-management-record-detail',
  templateUrl: './record-detail.component.html'
})
export class ParterRebateManageMenRecordDetailComponent implements OnInit {
  schema: SFSchema = {};
  columns!: STColumn[];
  ui!: SFUISchema;
  @ViewChild('st', { static: false })
  st!: STComponent;
  @ViewChild('sf', { static: false })
  sf!: SFComponent;
  spuStatus = '1';
  size: NzButtonSize = 'large';
  _$expand = false;
  record: any;
  data = [{ name1: 1111 }];
  constructor(public service: RebateManagementService, public shipperservice: ShipperBaseService, public modalRef: NzModalRef) {}
  /**
   * 查询字段个数
   */
  get queryFieldCount(): number {
    return Object.keys(this.schema?.properties || {}).length;
  }
  /**
   * 伸缩查询条件
   */
  expandToggle(): void {
    this._$expand = !this._$expand;
    this.sf?.setValue('/_$expand', this._$expand);
  }
  /**
   * 查询参数
   */
  get reqParams() {
    const params: any = Object.assign({}, this.sf?.value || {});
    delete params._$expand;
    return {
      partnerId: this.record.partnerId,
      ...params
    };
  }
  ngOnInit() {
    console.log(this.record);

    this.initSF();
    this.initST();
  }

  initSF() {
    this.schema = {
      properties: {
        ltdId: {
          type: 'string',
          title: '网络货运人',
          ui: {
            widget: 'select',
            placeholder: '请选择',
            allowClear: true,
            asyncData: () => this.shipperservice.getNetworkFreightForwarder(),
            change: (value: any) => {
              console.log(value);
              this.st.reload();
            }
          }
        },
        bankType: {
          title: '银行类型',
          type: 'string',
          enum: [
            {
              label: '全部',
              value: ''
            },
            {
              label: '平安银行',
              value: '1'
            },
            {
              label: '浦发银行',
              value: '2'
            }
          ],
          ui: {
            widget: 'select',
            containsAllLabel: true
          }
        }
      }
    };
    this.ui = {
      '*': {
        spanLabelFixed: 140,
        grid: { span: 8, gutter: 4 }
      }
    };
  }

  initST() {
    this.columns = [
      {
        title: '网络货运人',
        index: 'billCode'
      },
      {
        title: '订单号',
        index: 'billCode'
      },
      {
        title: '订单金额（元）',
        index: 'name1'
      },
      {
        title: '付款金额（元）',
        index: 'name1'
      },
      {
        title: '返佣金额（元）',
        index: 'name1'
      },
      {
        title: '附加费率',
        index: 'name1'
      },
      {
        title: '下单客户',
        index: 'name1'
      },
      {
        title: '银行类型',
        index: 'name1'
      },
      {
        title: '虚拟账户',
        index: 'name1'
      },
      {
        title: '返佣时间',
        index: 'name1'
      }
    ];
  }

  /**
   * 重置表单
   */
  resetSF() {
    this.sf.reset();
    this.st.load(1);
  }
  close() {
    this.modalRef.destroy();
  }
}
